﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Data.SqlClient;

namespace Forums
{
    public partial class ThreadPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (txtSubmitReply.Text.Length != 0)
            {
                lblReplyValidator.Visible = false;
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["CentForumsDB"].ConnectionString);
                cmd.CommandText = string.Format("INSERT INTO dbo.topic (refers_to, reply, date_posted, user_accnt, deleted) VALUES({0},'{1}', getdate(),{2}, 0)", Request.QueryString["topicId"], txtSubmitReply.Text, Session["user"]);

                try
                {
                    cmd.Connection.Open();
                    cmd.ExecuteNonQuery();
                    txtSubmitReply.Text = string.Empty;
                    Response.Redirect(string.Format("ThreadPage.aspx?topicId={0}", Request.QueryString["topicId"]));


                }
                catch (Exception ex)
                {


                }
                finally
                {
                    cmd.Connection.Close();
                }

            }
            else
            {
                lblReplyValidator.Text = "You must enter a reply";
                lblReplyValidator.Visible = true;

            }
        }

        protected void btnClear_Click(object sender, EventArgs e)
        {
            lblReplyValidator.Visible = false;
            txtSubmitReply.Text = string.Empty;
        }

    }
}
